old_posts/2017-2-23-Announcing Azure Functions support for Serverless Framework.html (80 lines of code) (raw):

--- layout: post hide_excerpt: true --- <html><head> <meta charset="utf-8"/> </head> <body> <div id="page"> <a class="url fn n profile-usercard-hover" href="https://social.msdn.microsoft.com/profile/Chris Anderson (Azure)" target="_blank">Chris Anderson (Azure)</a> <time> 2/23/2017 8:00:44 AM</time> <hr/> <div id="content">Today we’ve officially announced preview support for the Azure Functions Serverless Framework plugin. The Serverless Framework is an open source tool which allows you to deploy auto-scaling, pay-per-execution, event-driven functions to any cloud. It helps abstract away the details of your Serverless resources and lets you focus on the important part – your application. With the release of our new plugin, it’s one of the fastest ways to deploy a serverless application, ever. You can learn more about the plugin in the <a href="https://www.serverless.com/framework/docs/providers/azure/">Azure Functions Serverless Framework documentation</a>. You can also check out our npm package <a href="https://www.npmjs.com/package/serverless-azure-functions">serverless-azure-functions</a>. <h2 id="getting-started">Getting started</h2> Now let’s see a quick hello world example <h3 id="1-set-up-boilerplate">1. Set up boilerplate</h3> To setup the boilerplate, follow these instructions: <ol> <li>Recommend using Node v6.5.0</li> <li>Install the serverless tooling - <code>npm i -g serverless</code></li> <li>Create boilerplate (change <code>my-app</code> to whatever you'd prefer) -<code>serverless install --url https://github.com/azure/boilerplate-azurefunctions --name my-app</code></li> <li><code>cd my-app</code></li> <li><code>npm install</code></li> </ol> <h3 id="2-set-up-credentials">2. Set up credentials</h3> We'll set up an Azure Subscription and our service principal. You can learn more in the <a href="https://www.serverless.com/framework/docs/providers/azure/guide/credentials">credentials doc</a>. <ol> <li>Set up an Azure SubscriptionSign up for a free account @ <a href="https://azure.microsoft.com/en-us/services/functions/">https://azure.com</a>. Azure comes with a <a href="https://azure.microsoft.com/en-us/free/">free trial</a> that includes $200 of free credit.</li> </ol> <ol> <li>. Get the Azure CLI <pre><code class="lang-bash"> npm i -g azure-cli </code></pre> </li> <li>Login to Azure <pre><code class="lang-bash"> azure login </code></pre> This will give you a code and prompt you to visit <a href="https://aka.ms/devicelogin">aka.ms/devicelogin</a>. Provide the code and then login with your Azure identity (this may happen automatically if you're already logged in). You'll then be able to access your account via the CLI.</li> <li>Get your subcription and tenant id <pre><code class="lang-bash"> azure account show </code></pre> Save the subcription and tenant id for later</li> <li>Create a service principal for a given <code>&lt;name&gt;</code> and <code>&lt;password&gt;</code> and add contributor role. <pre><code class="lang-bash"> azure ad sp create -n &lt;name&gt; -p &lt;password&gt; </code></pre> This should return an object which has the <code>servicePrincipalNames</code> property on it and an ObjectId. Save the Object Id and one of the names in the array and the password you provided for later. If you need to look up your service principal later, you can use <code>azure ad sp -c &lt;name&gt;</code> where <code>&lt;name&gt;</code> is the name provided originally. Note that the <code>&lt;name&gt;</code> you provided is not the name you'll provide later, it is a name in the <code>servicePrincipalNames</code> array. Then grant the SP contributor access with the ObjectId <pre><code class="lang-bash"> azure role assignment create --objectId &lt;objectIDFromCreateStep&gt; -o Contributor </code></pre> </li> <li>Set up environment variablesYou need to set up environment variables for your subscription id, tenant id, service principal name, and password. <pre><code class="lang-bash"> # bash export azureSubId='&lt;subscriptionId&gt;' export azureServicePrincipalTenantId='&lt;tenantId&gt;' export azureServicePrincipalClientId='&lt;servicePrincipalName&gt;' export azureServicePrincipalPassword='&lt;password&gt;' </code></pre> <pre><code class="lang-powershell"> # PowerShell $env:azureSubId='&lt;subscriptionId&gt;' $env:azureServicePrincipalTenantId='&lt;tenantId&gt;' $env:azureServicePrincipalClientId='&lt;servicePrincipalName&gt;' $env:azureServicePrincipalPassword='&lt;password&gt;' </code></pre> </li> </ol> <h3 id="3-deploy-to-azure">3. Deploy to Azure</h3> Run the <a href="https://www.serverless.com/framework/docs/providers/azure/cli-reference/deploy">deploy command</a> <pre><code class="lang-bash">serverless deploy </code></pre> <h3 id="4-test">4. Test</h3> Run the <a href="https://www.serverless.com/framework/docs/providers/azure/cli-reference/invoke">invoke command</a> <pre><code class="lang-bash">serverless invoke function -f httpjs </code></pre></div> </div></body> <script src="{{ site.baseurl }}/resource/jquery-1.12.1.min.js" type="text/javascript"></script> <script src="{{ site.baseurl }}/resource/replace.js" type="text/javascript"></script> </html>